package org.jeecg.modules.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.RoleInfo;
import org.jeecg.modules.entity.DiyProfessiorPoint;
import org.jeecg.modules.entity.DiyProfessorInfo;
import org.jeecg.modules.entity.DiyProfessorScore;
import org.jeecg.modules.service.CallbackService;
import org.jeecg.modules.service.DiyProfessiorPointService;
import org.jeecg.modules.service.DiyProfessorScoreService;
import org.jeecg.modules.service.IDiyProfessorInfoService;
import org.jeecg.modules.temporary.entity.DiyTemporaryApplicantInfo;
import org.jeecg.modules.temporary.service.IDiyTemporaryApplicantInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author 86152
 * @date 2021/12/16 13:48:07
 */
@RestController
@RequestMapping("/gogo")
public class test {
    @Autowired
    private IDiyProfessorInfoService diyProfessorInfoService;
    @Autowired
    private IDiyTemporaryApplicantInfoService diyTemporaryApplicantInfoService;
    @Autowired
    private DiyProfessorScoreService diyProfessorScoreService;
    @Autowired
    private DiyProfessiorPointService diyProfessiorPointService;
    @Autowired
    private CallbackService callbackService;
    @Autowired
    private ISysBaseAPI iSysBaseAPI;
    // "白福昌","孙民强" ，"薛红新"
    static String[] zhuan1 = {"邓彩虹","刘勇","闫澍青","高微微","李宝宝","高宝生","刘元平","梁红星","王燕虹","王建云","雷宇珍","侯连连","白卯兵","王秀丽","辛怀亚","王全福","闫爱珍","刘宝贵","张翠萍","严鹏强","杜秀娟","马双提","卫志军","成旭梅","高全新"};
    static String[] zhuan = {"王小明","刘修权"};
    @GetMapping("/goto")
    public String noauth() throws Exception {
        for (int i = 0; i < zhuan.length; i++) {
            DiyTemporaryApplicantInfo one = diyTemporaryApplicantInfoService.getOne(new QueryWrapper<DiyTemporaryApplicantInfo>().eq("professor_name", zhuan[i]));
            DiyProfessorInfo diyProfessorInfo = new DiyProfessorInfo();
            DiyProfessorScore diyProfessorScore = new DiyProfessorScore();
            BeanUtils.copyProperties(one,diyProfessorInfo );
            BeanUtils.copyProperties(one,diyProfessorScore );
            diyProfessorInfo.setIsLeave(0);
            List<DiyProfessiorPoint> list = diyProfessiorPointService.list(new QueryWrapper<DiyProfessiorPoint>().eq("id", "2"));
            List<DiyProfessiorPoint> list2 = diyProfessiorPointService.list(new QueryWrapper<DiyProfessiorPoint>().eq("id", "1"));
            String str = "";
            if(list.get(0).getPointA().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointA();
            }
            if(list.get(0).getPointB().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointB();
            }
            if(list.get(0).getPointC().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointC();
            }
            if(list.get(0).getPointD().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointD();
            }
            if(list.get(0).getPointE().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointE();
            }
            if(list.get(0).getPointF().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointF();
            }
            diyProfessorScore.setTechnicalTitleScore(Integer.parseInt(str));
            diyProfessorScore.setFirstScore(60);
            diyProfessorScoreService.save(diyProfessorScore);
            diyProfessorInfoService.save(diyProfessorInfo);
            RoleInfo roleInfo = iSysBaseAPI.getRoleInfoByCode("professor");
            String roleId = roleInfo.getId();
            String uid = callbackService.getUidByUserId(one.getDingUserId());
            Integer integer = iSysBaseAPI.addRole(uid, roleId);
        }
        return "";
    }




    public DiyProfessorInfo noauth2(String name) throws Exception {
            DiyTemporaryApplicantInfo one = diyTemporaryApplicantInfoService.getOne(new QueryWrapper<DiyTemporaryApplicantInfo>().eq("professor_name", name));
            DiyProfessorInfo diyProfessorInfo = new DiyProfessorInfo();
            DiyProfessorScore diyProfessorScore = new DiyProfessorScore();
            BeanUtils.copyProperties(one,diyProfessorInfo );
            BeanUtils.copyProperties(one,diyProfessorScore );
            diyProfessorInfo.setIsLeave(0);
            List<DiyProfessiorPoint> list = diyProfessiorPointService.list(new QueryWrapper<DiyProfessiorPoint>().eq("id", "2"));
            List<DiyProfessiorPoint> list2 = diyProfessiorPointService.list(new QueryWrapper<DiyProfessiorPoint>().eq("id", "1"));
            String str = "";
            if(list.get(0).getPointA().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointA();
            }
            if(list.get(0).getPointB().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointB();
            }
            if(list.get(0).getPointC().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointC();
            }
            if(list.get(0).getPointD().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointD();
            }
            if(list.get(0).getPointE().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointE();
            }
            if(list.get(0).getPointF().equals(diyProfessorScore.getProfessorTitle()))
            {
                str=list2.get(0).getPointF();
            }
            diyProfessorScore.setTechnicalTitleScore(Integer.parseInt(str));
            diyProfessorScore.setFirstScore(60);
            diyProfessorScoreService.save(diyProfessorScore);
        return diyProfessorInfo;
    }
}
